package com.study.ioc.demo.beandefinitionregistrypostprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;

/**
 * registry为DefaultListableBeanFactory 可以注册BeanDefinition信息
 * 允许在正常的BeanFactoryPostProcessor检测开始之前注册更多的自定义bean。
 * 特别是，BeanDefinitionRegistryPostProcessor可以注册更多的bean定义，
 * 然后定义BeanFactoryPostProcessor实例。也就是说可以借此方法实现自定义的bean
 */
@Component
public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        //RootBeanDefinition user = new RootBeanDefinition(UserServiceImpl.class);
        //新增Bean定义
        //registry.registerBeanDefinition("user", user);
        String a = "123";
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }
}
